﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections;
using System.Globalization;
using DBAccess;
using SSPharma.Common;
using SSPharma.View;
using SSPharma.ViewModel;
using SSPharma.Biz;
using SSPharma.Common;

namespace SSPharma.View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class frmMainWindow : Window
    {
        public delegate void Button1_ClickedEventHandler(object sender);

        public frmMainWindow()
        {
           
            InitializeComponent();
        }
       
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            System.Windows.Application.Current.Shutdown();
            System.GC.Collect();
        }

        private void Button_Add_Click(object sender, EventArgs e)
        {
            try
            {
                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_ThemDuLieu();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }
        
        private void Button_Edit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_SuaDuLieu();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }
        
        private void Button_Delete_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_XoaDuLieu();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }

        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_LuuDuLieu();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }
  
        private void Button_ByPass_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_BoQua();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }

        private void Button_View_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_LuuDuLieu();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }

        private void Button_Print_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_InDuLieu();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }
        
        private void Button_Find_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ItemView = (MenuItemViewModel)tvDanhMuc.SelectedItem;
                dynamic uc = UtilityUIElement.GetUserControl(this.contentControl, ItemView.Views);
                uc.ev_TimKiem();
            }
            catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString()); }
        }

        private void Button_Exit_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.MessageBox.Show("Exit");
            DialogResult DR = System.Windows.Forms.MessageBox.Show("Bạn có muốn thoát khỏi chương trình không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
            if (DR == System.Windows.Forms.DialogResult.Yes)
            {
                this.OnClosed(e)  ; 
            }
           // var obj = type.TryCreateInstance(new[] { "foo", "bar" }, parameters); // first parameter is named "foo", second 
            
        }
    }
}
